package br.net.woodstock.tickettoride.orm;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import br.net.woodstock.rockframework.persistence.validator.jee.Reference;

@Entity
@Table(name = "ttr_session")
public class Session extends AbstractIntegerEntity {

	private static final long	serialVersionUID	= 8327197159799914755L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "session_id", unique = true)
	private Integer				id;

	@Column(name = "session_hash", length = 255, nullable = false)
	@NotNull
	@Size(min = 1, max = 255)
	private String				hash;

	@Column(name = "session_key", nullable = false)
	@Lob
	@Basic(fetch = FetchType.LAZY)
	@NotNull
	private byte[]				key;

	@ManyToOne(optional = false, fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "certificate_id", referencedColumnName = "certificate_id", nullable = false)
	@NotNull
	@Reference
	private Certificate			certificate;

	public Session() {
		super();
	}

	public Session(final Integer id) {
		super();
		this.id = id;
	}

	@Override
	public Integer getId() {
		return this.id;
	}

	@Override
	public void setId(final Integer id) {
		this.id = id;
	}

	public String getHash() {
		return this.hash;
	}

	public void setHash(final String hash) {
		this.hash = hash;
	}

	public byte[] getKey() {
		return this.key;
	}

	public void setKey(final byte[] key) {
		this.key = key;
	}

	public Certificate getCertificate() {
		return this.certificate;
	}

	public void setCertificate(final Certificate certificate) {
		this.certificate = certificate;
	}

}
